﻿using System;
using System.Drawing;
using System.IO;

namespace NExplorer
{
	public abstract class CommandBase : ICommand
	{
		public event EventHandler TextChanged;
		public event EventHandler ImageChanged;
		public event EventHandler EnabledChanged;

		private string	_text;
		private Image	_image;
		private bool	_enabled = true;

		protected CommandBase()
		{}

		protected CommandBase(string text)
			: this(text, null)
		{}

		protected CommandBase(string text, Image image)
		{
			_text = text;
			_image = image;
		}
		
		public virtual void Execute()
		{
			foreach (FileSystemInfo fileSystemInfo in ServiceManager.Explorer.SelectedItems)
			{
				Execute(fileSystemInfo);
			}
		}

		protected virtual void Execute(FileSystemInfo fileSystemInfo)
		{}

		public string Text
		{
			get { return _text; }

			protected set
			{
				if (_text != value)
				{
					_text = value;

					if (TextChanged != null)
					{
						TextChanged(this, EventArgs.Empty);
					}
				}
			}
		}

		public Image Image
		{
			get { return _image; }

			protected set
			{
				if (_image != value)
				{
					_image = value;

					if (ImageChanged != null)
					{
						ImageChanged(this, EventArgs.Empty);
					}
				}
			}
		}

		public bool Enabled
		{
			get { return _enabled; }
			protected set
			{
				if (_enabled != value)
				{
					_enabled = value;

					if (EnabledChanged != null)
					{
						EnabledChanged(this, EventArgs.Empty);
					}
				}
			}
		}

		public virtual void Dispose()
		{}
	}
}